package com.wangzifan.controller;

import com.wangzifan.entity.Course;
import com.wangzifan.entity.PageBean;
import com.wangzifan.entity.Result;
import com.wangzifan.entity.Teacher;
import com.wangzifan.service.CourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/courses")
public class CourseController {
    @Autowired
    private CourseService courseService;

    @GetMapping
    public Result queryCourse(@RequestParam(defaultValue = "1") Integer page,
                               @RequestParam(defaultValue = "10") Integer pageSize) {
        log.info("分页查询, 参数: {},{}",page,pageSize);
        PageBean pageBean = courseService.page(page,pageSize);
        return Result.success(pageBean);
    }

    @GetMapping("/{id}")
    public Result queryCourseById(@PathVariable Integer id) {
        Course course = courseService.queryCourseById(id);
        return Result.success(course);
    }

    @DeleteMapping("/{ids}")
    public Result deleteCourse(@PathVariable List<Integer> ids) {
        courseService.deleteCourse(ids);
        return Result.success();
    }

    @PostMapping()
    public Result addCourse(@RequestBody Course course) {
        courseService.addCourse(course);
        return Result.success();
    }

    @PutMapping()
    public Result updateCourse(@RequestBody Course course) {
        courseService.updateCourse(course);
        return Result.success();
    }
}
